<?php 
    class Search_model extends CI_Model
    {
        public function __construct() {
            parent::__construct();
        }
        public function getCenterForSearch($txtSearch)
        {
            $this->db->select('center.id_center, center.name, center.url_image');
            $this->db->from('center');
            $this->db->like('center.name', $txtSearch);
            
            $this->db->limit(4);
            $query = $this->db->get();
            if($query->num_rows()){
                return $query->result_array();
            }
            else{
                return NULL;
            }
        }
        public function getActForSearch($txtSearch)
        {
            $this->db->select('activity.id_activity, activity.name, activity.url_image');
            $this->db->from('activity');
            $this->db->like('activity.name', $txtSearch);
            
            $this->db->limit(4);
            $query = $this->db->get();
            if($query->num_rows()){
                return $query->result_array();
            }
            else{
                return NULL;
            }
        }
        public function getAddrForSearch($txtSearch)
        {
            $this->db->select('*');
            $this->db->from('center');
            $this->db->join('location', 'location.id_location = center.id_location');
            $this->db->like('location.num', $txtSearch);
            $this->db->or_like('location.street', $txtSearch);
            $this->db->or_like('location.ward', $txtSearch);
            $this->db->or_like('location.district', $txtSearch);
            $this->db->or_like('location.city', $txtSearch);
            $this->db->limit(4);
            $query = $this->db->get();
            if($query->num_rows()){
                return $query->result_array();
            }
            else{
                return NULL;
            }
        }
    }
?>